﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;


namespace ComLib.Web.Lib.Extensions
{
    /// <summary>
    /// Renders section with header/content
    /// </summary>
    public static class HtmlHelperExtensionsForShowHide
    {
        /// <summary>
        /// Renders a section with a header and content.
        /// </summary>
        /// <param name="htmlhelper"></param>
        /// <param name="header">Header for section</param>
        /// <param name="content">Content for section</param>
        /// <param name="sectionId">Optional Id for the section.</param>
        /// <param name="cssClassForSection">Optional css class for section</param>
        /// <param name="cssClassForHeader">Optional css class for header</param>
        /// <param name="cssClassForContent">Optional css class for content</param>
        /// <returns></returns>
        public static MvcHtmlString ShowHideAreaOn(this HtmlHelper htmlhelper, string header, string content,
            string sectionId, string cssClassForSection = "section",
            string cssClassForHeader = "section_head", string cssClassForContent = "section_body")
        {
            var html = string.Format(
                       @"<div id=""{0}"" class=""{1}"">"
                     + @"  <span id=""{2}"" class=""{3}"" onclick=""$('#{4}').toggle();"">{5}</span>"
                     + @"  <div id=""{6}"" class=""{7}"">{8}</div>"
                     + @"</div>",
                     sectionId, cssClassForSection,
                    sectionId + "_head", cssClassForHeader, sectionId + "_body", header,
                    sectionId + "_body", cssClassForContent, content);
            return MvcHtmlString.Create(html);
        }
    }
}
